/* -------------------------------------------------------------------------- *
   TestWinUnit - Maria Blees (maria.blees@microsoft.com)

   File: ToStringTest.cpp

   This file contains tests for ToString implementations.
   We want to be able to accommodate all the types found in
   http://msdn2.microsoft.com/en-us/library/s3f49ktz(vs.80).aspx .
 * -------------------------------------------------------------------------- */
#include "WinUnit.h"

using namespace WinUnit;

namespace
{
    TCHAR s_buffer[256] = _T("");
}

#pragma warning(push)
#pragma warning(disable : 4702)

// pointer
BEGIN_TEST(ToStringPointer)
{
    int n = 5;
    int* pn = &n;
    WIN_TRACE("INFO: Next line should display a pointer value.\n");
    WIN_TRACE(_T("OUTPUT: %s.\n"), ToString(pn, s_buffer, 256));
}
END_TEST

// int (a.k.a. signed)
BEGIN_TEST(ToStringIntMax)
{
    int n = INT_MAX;
    WIN_TRACE("INFO: Next line should output an integer (INT_MAX) (%d).\n", INT_MAX);
    WIN_TRACE(_T("OUTPUT: %s.\n"), ToString(n, s_buffer, 256));
}
END_TEST

BEGIN_TEST(ToStringIntMin)
{
    int n = INT_MIN;
    WIN_TRACE("INFO: Next line should output an integer (INT_MIN) (%d).\n", INT_MIN);
    WIN_TRACE(_T("OUTPUT: %s.\n"), ToString(n, s_buffer, 256));
}
END_TEST

// unsigned int (a.k.a. unsigned)
BEGIN_TEST(ToStringUnsignedInt)
{
    unsigned int n = UINT_MAX;
    WIN_TRACE("INFO: Next line should output an unsigned int (UINT_MAX) (%d).\n", UINT_MAX);
    WIN_TRACE(_T("OUTPUT: %s.\n"), ToString(n, s_buffer, 256));
}
END_TEST

// __int8 (a.k.a. char)
BEGIN_TEST(ToStringInt8Max)
{
    __int8 n = 127;
    WIN_TRACE("INFO: Next line should output an __int8 (same as a char) (127).\n");
    WIN_TRACE(_T("OUTPUT: %s.\n"), ToString(n, s_buffer, 256));
}
END_TEST

// __int8 (a.k.a. char)
BEGIN_TEST(ToStringInt8Min)
{
    __int8 n = -127;
    WIN_TRACE("INFO: Next line should output an __int8 (same as a char) (-127).\n");
    WIN_TRACE(_T("OUTPUT: %s.\n"), ToString(n, s_buffer, 256));
}
END_TEST

// unsigned __int8 (a.k.a. unsigned char)
BEGIN_TEST(ToStringUnsignedInt8)
{
    unsigned __int8 n = 255;
    WIN_TRACE("INFO: Next line should output an unsigned __int8 (same as a char) (255).\n");
    WIN_TRACE(_T("OUTPUT: %s.\n"), ToString(n, s_buffer, 256));
}
END_TEST

// __int16 (a.k.a. short, short int, signed short int)
BEGIN_TEST(ToStringInt16)
{
    __int16 n = -32000;
    WIN_TRACE("INFO: Next line should output a short (-32000).\n");
    WIN_TRACE(_T("OUTPUT: %s.\n"), ToString(n, s_buffer, 256));
}
END_TEST

// unsigned __int16 (a.k.a. unsigned short, unsigned short int)
BEGIN_TEST(ToStringUnsignedInt16)
{
    unsigned __int16 n = 65000;
    WIN_TRACE("INFO: Next line should output an unsigned short (65000).\n");
    WIN_TRACE(_T("OUTPUT: %s.\n"), ToString(n, s_buffer, 256));
}
END_TEST

// __int32 (a.k.a. signed, signed int, int)
BEGIN_TEST(ToStringInt32)
{
    __int32 n = -5;
    WIN_TRACE("INFO: Next line should output an __int32 (-5).\n");
    WIN_TRACE(_T("OUTPUT: %s.\n"), ToString(n, s_buffer, 256));
}
END_TEST

// unsigned __int32 (a.k.a. unsigned, unsigned int)
BEGIN_TEST(ToStringUnsignedInt32)
{
    unsigned __int32 n = (unsigned __int32)-5;
    WIN_TRACE("INFO: Next line should output an unsigned __int32 (-5, but unsigned).\n");
    WIN_TRACE(_T("OUTPUT: %s.\n"), ToString(n, s_buffer, 256));
}
END_TEST

// __int64 (a.k.a. long long, signed long long)
BEGIN_TEST(ToStringInt64)
{
    __int64 n = 9223372036854775807;
    WIN_TRACE("INFO: Next line should output an __int64 (9223372036854775807).\n");
    WIN_TRACE(_T("OUTPUT: %s.\n"), ToString(n, s_buffer, 256));
}
END_TEST

// unsigned __int64 (a.k.a. unsigned long long)
BEGIN_TEST(ToStringUnsignedInt64)
{
    unsigned __int64 n = (unsigned __int64)-9223372036854775800;
    WIN_TRACE("INFO: Next line should output an unsigned __int64 (-9223372036854775800, unsigned).\n");
    WIN_TRACE(_T("OUTPUT: %s.\n"), ToString(n, s_buffer, 256));
}
END_TEST

// bool (1)
BEGIN_TEST(ToStringBoolTrue)
{
    bool n = true;
    WIN_TRACE("INFO: Next line should output a bool (true).\n");
    WIN_TRACE(_T("OUTPUT: %s.\n"), ToString(n, s_buffer, 256));
}
END_TEST

BEGIN_TEST(ToStringBoolFalse)
{
    bool n = false;
    WIN_TRACE("INFO: Next line should output a bool (false).\n");
    WIN_TRACE(_T("OUTPUT: %s.\n"), ToString(n, s_buffer, 256));
}
END_TEST

// char (1)
BEGIN_TEST(ToStringChar)
{
    char n = 'A';
    WIN_TRACE("INFO: Next line should output a char ('A').\n");
    WIN_TRACE(_T("OUTPUT: %s.\n"), ToString(n, s_buffer, 256));
}
END_TEST

// signed char (1)
BEGIN_TEST(ToStringSignedChar)
{
    signed char n = (signed char)'A';
    WIN_TRACE("INFO: Next line should output a signed char ('A').\n");
    WIN_TRACE(_T("OUTPUT: %s.\n"), ToString(n, s_buffer, 256));
}
END_TEST

BEGIN_TEST(ToStringSignedCharUnprintable)
{
    signed char n = (signed char)'\n';
    WIN_TRACE("INFO: Next line should output the sign for an unprintable character (.).\n");
    WIN_TRACE(_T("OUTPUT: %s.\n"), ToString(n, s_buffer, 256));
}
END_TEST

// unsigned char (1)
BEGIN_TEST(ToStringUnsignedChar)
{
    unsigned char n = (unsigned char)'A';
    WIN_TRACE("INFO: Next line should output an unsigned char ('A').\n");
    WIN_TRACE(_T("OUTPUT: %s.\n"), ToString(n, s_buffer, 256));
}
END_TEST

// short (2)
BEGIN_TEST(ToStringShort)
{
    short n = 5;
    WIN_TRACE("INFO: Next line should output a short (5).\n");
    WIN_TRACE(_T("OUTPUT: %s.\n"), ToString(n, s_buffer, 256));
}
END_TEST

// unsigned short (2) 
BEGIN_TEST(ToStringUnsignedShort)
{
    unsigned short n = 5;
    WIN_TRACE("INFO: Next line should output an unsigned short (5).\n");
    WIN_TRACE(_T("OUTPUT: %s.\n"), ToString(n, s_buffer, 256));
}
END_TEST

// long (4)
BEGIN_TEST(ToStringLong)
{
    long n = 5;
    WIN_TRACE("INFO: Next line should output a long (5).\n");
    WIN_TRACE(_T("OUTPUT: %s.\n"), ToString(n, s_buffer, 256));
}
END_TEST

// unsigned long (4)
BEGIN_TEST(ToStringUnsignedLong)
{
    unsigned long n = 5;
    WIN_TRACE("INFO: Next line should output an unsigned long (5).\n");
    WIN_TRACE(_T("OUTPUT: %s.\n"), ToString(n, s_buffer, 256));
}
END_TEST

// long long (8) 
BEGIN_TEST(ToStringLongLong)
{
    long long n = 5;
    WIN_TRACE("INFO: Next line should output a long long (5).\n");
    WIN_TRACE(_T("OUTPUT: %s.\n"), ToString(n, s_buffer, 256));
}
END_TEST

// unsigned long long (8) 
BEGIN_TEST(ToStringUnsignedLongLong)
{
    unsigned long long n = 5;
    WIN_TRACE("INFO: Next line should output an unsigned long long (5).\n");
    WIN_TRACE(_T("OUTPUT: %s.\n"), ToString(n, s_buffer, 256));
}
END_TEST

// float (4)
BEGIN_TEST(ToStringFloat)
{
    float n = 5.5;
    WIN_TRACE("INFO: Next line should output a float (5.5).\n");
    WIN_TRACE(_T("OUTPUT: %s.\n"), ToString(n, s_buffer, 256));
}
END_TEST

// double (8)
BEGIN_TEST(ToStringDouble)
{
    double n = 5.5;
    WIN_TRACE("INFO: Next line should output a double (5.5).\n");
    WIN_TRACE(_T("OUTPUT: %s.\n"), ToString(n, s_buffer, 256));
}
END_TEST

// long double (same as double)
BEGIN_TEST(ToStringLongDouble)
{
    long double n = 5.5;
    WIN_TRACE("INFO: Next line should output a long double (5.5).\n");
    WIN_TRACE(_T("OUTPUT: %s.\n"), ToString(n, s_buffer, 256));
}
END_TEST

// wchar_t (2)
BEGIN_TEST(ToStringWchar)
{
    wchar_t n = L'A';
    WIN_TRACE("INFO: Next line should output a wchar_t ('A').\n");
    WIN_TRACE(_T("OUTPUT: %s.\n"), ToString(n, s_buffer, 256));
}
END_TEST

BEGIN_TEST(ToStringWcharUnprintable)
{
    wchar_t n = L'\n';
    WIN_TRACE("INFO: Next line should output the sign for an unprintable character (.).\n");
    WIN_TRACE(_T("OUTPUT: %s.\n"), ToString(n, s_buffer, 256));
}
END_TEST

#pragma warning(pop)